/*************************************************************************
	> File Name: write.c
	> Author: life
	> Created Time: 2021年03月13日 星期六 15时41分35秒
 ************************************************************************/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

int main(void)
{
	int fd;
	int flags;
	char buf[10]="abcdefg";
	size_t size;	
	off_t currpos;
	fd = open("./file.txt",O_CREAT,0664);
	if(fd < 0)
	{
		printf("open fild");
		return -1;
	}
	currpos = lseek(fd, 0, SEEK_CUR); //设置打开时的偏移量
	printf("currpos:%ld\n",currpos);
#if 0
	flags = fcntl(fd,F_GETFL);
	flags |= O_RDWR;
	if(fcntl(fd ,F_SETFL,flags) < 0 )
	{
		perror("fcntl");
		exit(1);
	}
#endif
	size = write(fd,buf,10);
	if(size < 0)
	{
		printf("write fild");
	}
	close(fd);

	printf("size = %ld,buf:%s\n",size,buf);
	return 0;
}
